﻿using CSharp.Study.SignalRTest.Hubs;
using CSharp.Study.SignalRTest.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System.Diagnostics;

namespace CSharp.Study.SignalRTest.Controllers
{
    [Route("[controller]/[action]")]
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IHubContext<ChatHub> _chathub;
        public HomeController(ILogger<HomeController> logger,IHubContext<ChatHub> chathub)
        {
            _logger = logger;
            _chathub = chathub;
        }

        public IActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public async Task SendMsg()
        {
            await _chathub.Clients.All.SendAsync("ReceiveMsg", "km", "666");
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}